<template>
  <el-table
    ref="table"
    v-loading="page.loading"
    border
    :data="tableData"
    row-key="System_10_10"
    height="100%"
    style="position:absolute"
    highlight-current-row
    @row-click="OnrowClick"
    @selection-change="onSelectionChange"
    @select="onSelect"
    @select-all="onSelect"
  >
    <el-table-column v-if="showselect" type="selection" width="40">
    </el-table-column>
    <el-table-column type="index" width="40"> </el-table-column>
    <el-table-column prop="SYS_ASSET_A1_50" label="字段">
      <template slot="header" slot-scope="scope">
        <el-input
          v-model="page.search"
          size="small"
          placeholder="输入关键字搜索"
          clearable
        />
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { AssetA1 } from "@/api";
export default {
  data() {
    return {
      //页面控制
      page: {
        loading: true,
        search: ""
      },
      //数据
      data: {
        sysAssetA1Data: []
      }
    };
  },
  //外部属性
  props: {
    showselect: {
      type: Boolean,
      default() {
        return false;
      }
    }
  },
  //内部方法
  methods: {
    async initPage() {
      this.data.sysAssetA1Data = await AssetA1.GetSysAssetA2();
      this.$nextTick(() => {
        this.page.loading = false;
      });
    },
    OnrowClick(row) {
      this.$emit("rowClick", row);
    },
    onSelectionChange(rows) {
      this.$emit("onSelectionChange", rows);
    },
    onSelect(rows, row) {
      if (rows.length == 0) {
        this.$emit("onSelectClear");
        return;
      }
      if (row) {
        const selected = rows.includes(row);
        this.$emit("onSelect", rows, row, selected);
      } else {
        rows.forEach(item => {
          const selected = true;
          this.$emit("onSelect", rows, item, selected);
        });
      }
    }
  },
  //组件
  components: {},
  //初始化 异步加async await
  mounted() {
    this.initPage();
  },
  //计算属性
  computed: {
    //分页后的数据
    tableData() {
      let _data = [];
      _data = this.data.sysAssetA1Data;
      if (this.page.search) {
        _data = _data.search({
          SYS_ASSET_A1_50: val => val.includes(this.page.search)
        });
      }
      return _data;
    }
  },
  //监视
  watch: {}
};
</script>

<style lang="scss" scoped>
@import "@/style/base.scss";
</style>
